﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Noodles.Core.Repositories;
using Noodles.Core.Model;


namespace NoodlesCms.Areas.Admin.Controllers
{
    public class LoginController : Controller
    {
        public ILoginRepository Repository { get; set; }
        //
        // GET: /Admin/Login/
      
         [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(UserMaster Login)
        {
            var loginProvider = DependencyResolver.Current.GetService<Noodles.Core.Repositories.ILoginRepository>();
            bool isValid = loginProvider.ValidateLogIn(Login.Username, Login.Password);

            if (isValid)
            {
                ViewData["UserName"] = Login.Username; 
                Session["adminid"] = Login.Username;
                return RedirectToAction("Index", "Admin", new { area = "Admin" });
            }
           
           ModelState.AddModelError(string.Empty, "Wrong User name or Password !!");
            return View(Login);
        }


    }
}
